package com.dcbeida.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.dcbeida.R;
import com.dcbeida.bean.SalsesDetail;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 我的客户详情
 */
public class MyClientDetailAdapter extends BaseAdapter {

    private ArrayList<SalsesDetail.ListBean> mArrayList = new ArrayList<>();
    private Context mContext;

    public MyClientDetailAdapter(Context context) {
        super();
        this.mContext = context;
    }


    @Override
    public int getCount() {
        if (mArrayList == null) {
            return 0;
        } else {
            return this.mArrayList.size();
        }
    }

    @Override
    public Object getItem(int position) {
        if (mArrayList == null) {
            return null;
        } else {
            return this.mArrayList.get(position);
        }
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.my_client_detail_item, null, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        SalsesDetail.ListBean bean = mArrayList.get(position);
        holder.tvPh.setText(mContext.getString(R.string.ph)+bean.getBatchnumber());
        holder.tvYxq.setText(mContext.getString(R.string.yxq)+bean.getExpiredate());
        holder.tv3.setText(bean.getDrugcode());
        holder.tv4.setText(bean.getQuantity());
        holder.tvDdbh.setText(mContext.getString(R.string.ddbh)+bean.getOrderid());//订单id没有
        holder.tvGmsj.setText(mContext.getString(R.string.gmrq)+bean.getCreatetime());


        return convertView;
    }


    public ArrayList<SalsesDetail.ListBean> getmArrayList() {
        return mArrayList;
    }

    public void setmArrayList(ArrayList<SalsesDetail.ListBean> mArrayList) {
        if (mArrayList.size() >= 0) {
            this.mArrayList.addAll(mArrayList);
        }
        notifyDataSetChanged();
    }

    public void clearList() {
        this.mArrayList.clear();
    }


    static class ViewHolder {

        @Bind(R.id.tv_ph)
        TextView tvPh;
        @Bind(R.id.tv_yxq)
        TextView tvYxq;
        @Bind(R.id.tv3)
        TextView tv3;
        @Bind(R.id.tv4)
        TextView tv4;
        @Bind(R.id.tv_ddbh)
        TextView tvDdbh;
        @Bind(R.id.tv_gmsj)
        TextView tvGmsj;
        
        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }

}
